package com.kuang.stream;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * Stream流式计算
 *
 * 题目要求：一行代码实现
 * 1.ID必须是偶数
 * 2、年龄必须大于23岁
 * 3、用户名转为大写字母
 * 4、用户名字母倒着排序
 * 5、只输出一个用户！
 */
public class Test {
    public static void main(String[] args) {
        User user1 = new User(1,"zhao", 23);
        User user2 = new User(2,"wang", 21);
        User user3 = new User(3,"li", 19);
        User user4 = new User(4,"song", 26);
        User user5 = new User(5,"pan", 19);
        //集合就是存储
        List<User> userList = Arrays.asList(user1, user2, user3, user4, user5);

        userList.stream()
                .filter(e-> e.getAge()%2 == 0)
                .filter(e-> e.getAge()>23)
                .map(e-> e.getName().toUpperCase())
                .sorted(Comparator.reverseOrder())
                .limit(1)
                .forEach(System.out::println);

    }
}

@Data//代表getter,setter
@AllArgsConstructor//有参构造
@NoArgsConstructor//无参构造
@ToString //tosstring的注解
class User{
    private int id;
    private String name;
    private Integer age;
}
